package com.ebocy.hammer.world.message;

import com.ebocy.hammer.core.constants.GameMessageCode;
import com.ebocy.hammer.core.domain.GamePlayer;
import com.ebocy.hammer.core.message.AbstractS2CMessage;

public class S2CRoomMemberUpdateMessage extends AbstractS2CMessage {
	public static final byte INCREASE = 1;
	public static final byte DECREASE = 2;

	private byte type;
	private long playerId;
	private String name;
	private String icon;
	private int roleImage;
	private int hammerId;

	public S2CRoomMemberUpdateMessage(GamePlayer gamePlayer, byte type) {
		this.type = type;
		this.playerId = gamePlayer.getGamePlayerId();
		this.name = gamePlayer.getName();
		this.icon = gamePlayer.getHeadPortrait();
		this.roleImage = gamePlayer.getRoleImage();
		this.hammerId = gamePlayer.getHammerId();
	}

	@Override
	protected void writeMessage() {
		writeByte(type);
		writeString(String.valueOf(playerId));
		if (type == INCREASE) {
			writeString(name);
			writeString(icon);
			writeInt(roleImage);
			writeInt(hammerId);
		}
	}

	@Override
	public short getMessageCode() {
		return GameMessageCode.WORLD_4V4_ROOM_UPDATE;
	}

}
